package com.village.friend.fifter;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Package: com.*.*.config
 * @ClassName: LoginConfig
 * @Description:拦截器配置
 * @author: zk
 * @date: 2021年8月12日15:38:00
 */
@Configuration
public class LoginConfig implements WebMvcConfigurer {

    /**
     * @Function: 这个方法才能在拦截器中自动注入查询数据库的对象
     * @author: YangXueFeng
     * @Date: 2019/4/14 13:10
     */
    @Bean
    AuthInterceptor loginInterceptor() {
        return new AuthInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        //注册TestInterceptor拦截器
        InterceptorRegistration registration = registry.addInterceptor(loginInterceptor());
        registration.addPathPatterns("/**");
        registration.excludePathPatterns(
                // 静态资源
                "/**/*.html",
                "/**/img/**",
                "/**/css/**",
                "/**/*.js",
                "/**/*.css",
                "/**/*.woff",
                "/**/*.png",
                "/**/*.ttf",
                "/**/*.ico",
                //swagger相关信息
                "/**/swagger-resources/**",
                "/**/webjars/**",
                "/api/v2/**",
                "/**/swagger-ui.html/**",
                "/**/csrff",
                "/**/error",
                "/api/",
                //登录前不需要token的接口
                "/**/user/sendAuthCode",
                "/**/user/login",
                "/**/user/updateUserGender",
                //短信测试接口过滤
                "/**/user/testMsg",
                "/**/home/ping",
                "/**/home/tokenCheck",
                "/**/notify/aliPayNotifyRes",
                "/**/notify/wxPayNotifyRes"

        );
    }
}
